home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frmTrapMouse
- BorderStyle = 1 'Fixed Single
- Caption = "ClipCursor Demo"
- ClientHeight = 1800
- ClientLeft = 1980
- ClientTop = 2520
- ClientWidth = 4590
- Icon = "TrapMouse.frx":0000
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 1800
- ScaleWidth = 4590
- Begin VB.CommandButton cmdCommandTrap
- Caption = "Trap To Command Button"
- Height = 735
- Left = 120
- TabIndex = 3
- Top = 840
- Width = 1215
- End
- Begin VB.Frame fraTrap
- Caption = "Frame"
- Height = 1575
- Left = 1560
- TabIndex = 1
- Top = 120
- Width = 2775
- Begin VB.CommandButton cmdFrameTrap
- Caption = "Trap To Frame"
- Height = 375
- Left = 1440
- TabIndex = 2
- Top = 1080
- Width = 1215
- End
- End
- Begin VB.CommandButton cmdFormTrap
- Caption = "Trap To Form"
- Height = 495
- Left = 120
- TabIndex = 0
- Top = 120
- Width = 1215
- End
- Attribute VB_Name = "frmTrapMouse"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- '''''''''''''''''''''''''''''''''''''''''''''
- ' Clip Cursor Demo by: Steve Weller
- ' E-Mail: TheVBFreak13@aol.com
- ' Purpose: to demonstrate the ClipCursor API
- ' function and its various uses (it can be
- ' used with any control as long as left and
- ' top are supplied). Also resets the
- ' clipping when the program is exited.
- ' Date Created: October 16, 1999
- Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
- Private Type RECT
- Left As Long
- Top As Long
- Right As Long
- Bottom As Long
- End Type
- Private Sub cmdCommandTrap_Click()
- ' trap cursor to command button
- Dim Rct As RECT, X%, Y%
- X = Screen.TwipsPerPixelX
- Y = Screen.TwipsPerPixelY
- If cmdCommandTrap.Caption = "Trap To Command Button" Then
- ' values are adjusted so cursor is clipped correctly
- ' DO NOT CHANGE!!
- With Rct
- .Left = ((Me.Left + cmdCommandTrap.Left) / X) + 4
- .Top = ((Me.Top + cmdCommandTrap.Top) / Y) + 24
- .Right = .Left + cmdCommandTrap.Width / X
- .Bottom = (.Top + cmdCommandTrap.Height / Y) - 2
- End With
- cmdFrameTrap.Enabled = False
- cmdFormTrap.Enabled = False
- ClipCursor Rct
- cmdCommandTrap.Caption = "Untrap"
- With Rct
- .Left = 0
- .Top = 0
- .Right = Screen.Width / X
- .Bottom = Screen.Height / Y
- End With
- cmdFrameTrap.Enabled = True
- cmdFormTrap.Enabled = True
- ClipCursor Rct
- cmdCommandTrap.Caption = "Trap To Command Button"
- End If
- End Sub
- Private Sub cmdFormTrap_Click()
- ' traps the cursor to the form
- Dim Rct As RECT, X%, Y%
- X = Screen.TwipsPerPixelX
- Y = Screen.TwipsPerPixelY
- If cmdFormTrap.Caption = "Trap To Form" Then
- With Rct
- .Left = Me.Left / X
- .Top = Me.Top / Y
- .Right = .Left + Me.Width / X
- .Bottom = .Top + Me.Height / Y
- End With
- cmdFrameTrap.Enabled = False
- cmdCommandTrap.Enabled = False
- ClipCursor Rct
- cmdFormTrap.Caption = "Untrap"
- With Rct
- .Left = 0
- .Top = 0
- .Right = Screen.Width / X
- .Bottom = Screen.Height / Y
- End With
- cmdFrameTrap.Enabled = True
- cmdCommandTrap.Enabled = True
- ClipCursor Rct
- cmdFormTrap.Caption = "Trap To Form"
- End If
- End Sub
- Private Sub cmdFrameTrap_Click()
- ' trap cursor to frame
- Dim Rct As RECT, X%, Y%
- X = Screen.TwipsPerPixelX
- Y = Screen.TwipsPerPixelY
- If cmdFrameTrap.Caption = "Trap To Frame" Then
- ' values are adjusted so cursor is clipped correctly
- ' DO NOT CHANGE!!
- With Rct
- .Left = ((Me.Left + fraTrap.Left) / X) + 4
- .Top = ((Me.Top + fraTrap.Top) / Y) + 24
- .Right = .Left + fraTrap.Width / X
- .Bottom = (.Top + fraTrap.Height / Y) - 2
- End With
- cmdCommandTrap.Enabled = False
- cmdFormTrap.Enabled = False
- ClipCursor Rct
- cmdFrameTrap.Caption = "Untrap"
- With Rct
- .Left = 0
- .Top = 0
- .Right = Screen.Width / X
- .Bottom = Screen.Height / Y
- End With
- cmdCommandTrap.Enabled = True
- cmdFormTrap.Enabled = True
- ClipCursor Rct
- cmdFrameTrap.Caption = "Trap To Frame"
- End If
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- ' reset the clipped cursor in case a user
- ' tries to exit after clicking a "Trap" button
- Dim Rct As RECT
- With Rct
- .Left = 0
- .Top = 0
- .Right = Screen.Width / Screen.TwipsPerPixelX
- .Bottom = Screen.Height / Screen.TwipsPerPixelY
- End With
- ClipCursor Rct
- End Sub
-